
function getLoginStatus(account,login_id,parseFunc) {
//	if(g_msg) return;
	$.ajax({ 
		type: "post", 
		url: "/service/", 
		dataType: "json", 
		timeout:25000,
		async:true,
		data: {"act": "getstatus","login_id": login_id,"account":account},
		success: function (data,textStatus) { 
			if(data != null && parseFunc != null)
			{
				parseFunc(data);
			}
			setTimeout(function () { 
			getLoginStatus(account, login_id, parseFunc);	
			}, 500);				
		}, 
		 complete:function(XMLHttpRequest,textStatus){  
					if(XMLHttpRequest.readyState=="4"){  
						//alert(XMLHttpRequest.responseText);  
					}  
			},  		
		error: function (XMLHttpRequest, textStatus, errorThrown) { 
				setTimeout(function () { 
				getLoginStatus(account, login_id, parseFunc);	
				}, 1000);	
			if (textStatus == "timeout") { // 请求超时
					  // 递归调用
				// 其他错误，如网络错误等
				} else { 
				}
		} 
	});
}

function parseLoginStatus(data){
	if(data.r ==1){
		var url = "/service/?act=webmsg&sid="+data.sid+"&peer_sid="+data.peer_sid;
		//newWindows(data.sid,url);
		openTab(data.peer_sid,url);
		//showMessageDialog(url,data.sid,"message",900,400,false);
	}else if(data.r == 2){//添加客户信息URL
		var mapsid = getUrlParam(data.url,"mapsid");
		showMessageDialog(data.url,mapsid,'添加客户信息',500,350,true);
	}
}
function newWindows(sid, url ){	
	$('#open_msg_link').attr("target",sid);
	$('#open_msg_link').attr("href",url);
	document.getElementById("open_msg_link").click();
}
function showMessageDialog(url, sid, title, width, height, shadow) {  
    var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';  
    var boarddiv = '<div id="'+ sid +'" title="' + title + '"></div>'//style="overflow:hidden;"可以去掉滚动条  
	var qCtlid = '#'+sid;
	var win;
    $(document.body).append(boarddiv);  
	 win = $(qCtlid).dialog({  
		content: content,  
		width: width,  
		height: height,  
		modal: shadow,  
		title: title,  
		onClose: function () {  
			$(this).dialog('destroy');//后面可以关闭后的事件  
		}  
	});  
    win.dialog('open');  
} 

function sendCmd(strUrl,sentData,resultCallback)
{
	var nResult = -99;
	var bSync = false;
	$.ajax({ 
		type: "post", 
		url: strUrl, 
		dataType: "json", 
		data: sentData,
		async:false,
		success: function (data,textStatus) { 
			bSync = true;
			nResult = data.result;
			if(resultCallback!="" && resultCallback != null)
				resultCallback(nResult);
			return nResult;
		}, 
		 complete:function(XMLHttpRequest,textStatus){  
					if(XMLHttpRequest.readyState=="4"){  
						//alert(XMLHttpRequest.responseText);  
					}  
			},  		
		error: function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("网络错误! " + textStatus + ", error: " + errorThrown );
			if (textStatus == "timeout") { // 请求超时
				// 其他错误，如网络错误等
				} else { 
				}
			bSync = true;
		} 
	});	
	return nResult;
}

function manager_customer(login_id)
{
	$.post('/service/', {"act":"customer_m","login_id":login_id},
	   function(data){
		 //alert(data.reason); // 
		 if(data.r == 0)
		 {
			 openTab('客户管理',data.url);
		}
	   }, "json");	
	   return ;
}

function offlineMsg_m(login_id)
{
	$.post('/service/', {"act":"offlinemsg_m","login_id":login_id},
	   function(data){
		 //alert(data.reason); // 
		 if(data.r == 0)
		 {
			 openTab('留言管理',data.url);
		}
	   }, "json");	
	   return ;
}

function getUrlParam(strUrl , name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = strUrl.match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}